<template>
  <div>
    <!-- 顶部 -->
    <van-nav-bar
      title="传智播客.黑马程序员Vue.js"
      style="background-color: #26a2ff; margin-bottom: 5px"
    />
    <!-- 头部 -->
    <div class="header">
      <van-nav-bar
        title="商品图文页"
        left-text="返回"
        left-arrow
        @click-left="$router.back()"
      >
        <template #right>
          <van-icon
            name="wap-home-o"
            size="18"
            @click="$router.push({ name: 'Home' })"
          />
        </template>
      </van-nav-bar>
    </div>

    <div class="title">{{ descData.title }}</div>
    <div class="line"></div>
    <div class="comment" v-html="descData.content"></div>
  </div>
</template>

<script>
import { getdesc } from "@/apis/goods";
export default {
  data() {
    return {
      descData: {},
    };
  },
  async created() {
    // 根据id获取图文详情。
    const id = this.$route.params.id;
    const getdescData = await getdesc(id);
    this.descData = getdescData.data.message[0];
  },
  mounted() {
    setTimeout(() => {
      let imgs = document.querySelectorAll("p img");
      for (let i = 0; i < imgs.length; i++) {
        imgs[i].setAttribute("width", "100%");
        imgs[i].removeAttribute("height");
      }
    }, 10);
  },
};
</script>

<style lang="less" scoped>
/deep/ .van-nav-bar__title {
  color: #fff;
}
.header {
  /deep/ .van-nav-bar__title {
    color: #1989fa;
  }
  /deep/ .van-nav-bar {
    background-color: #f7f7f7;
  }
}

.title {
  color: #50b9e9;
  font-size: 18/360 * 100vw;
  line-height: 25px;
  margin-bottom: 10/360 * 100vw;
  height: 60/360 * 100vw;
  font-weight: 900;
  padding: 10px 10px 10px 10px;
  box-sizing: border-box;
}
.line {
  width: 100%;
  border: grey 1px solid;
  margin-bottom: 15px;
}
/deep/.comment > p {
  font-size: 16/360 * 100vw;
  line-height: 20px;
  padding: 0 5px;
  img {
    width: 100%;
  }
}
.comment {
  /deep/table {
    width: 100%;
    tbody {
      padding: 0 5px;
      text-align: left;
      tr {
        width: 360px;
        td {
          float: left;
          width: 100%;
          text-align: center;
          img {
            width: 100%;
          }
          span {
            text-align: left;
          }
        }
      }
    }
  }
}
</style>
